# coding=utf-8
import traceback
import requests
import unittest
from Common.FontColor import outcome
from Common.MyUnit import MyTest
from random import choice
from Common.CusMethod import random_code, random_str
from Common.ReadYaml import ConfigYaml,ReadKeyWorld
from Common.DataHandle import ReRun
from ERP.backlog.Public import BacklogData

backlog = BacklogData()


class management_backlog(MyTest):

    '''
    检核工作台
    '''

    @ReRun(MyTest.setUp)
    def test_review_todo(self):
        '''
        case51 待检核列表
        reviewStatus=0: 待检核
        '''
        r = backlog.review_query(reviewStatus=0)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        re_len = len(res['data']['list'])
        if re_len > 0:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_review_no(self):
        """case52 已检核未调整
        reviewStatus=1: 已检核未调整
        """
        r = backlog.review_query(reviewStatus=1)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        re_len = len(res['data']['list'])
        if re_len > 0:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_review_done(self):
        """case53 已检核已调整列表
        reviewStatus=2: 已检核已调整
        """
        r = backlog.review_query(reviewStatus=2)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        re_len = len(res['data']['list'])
        if re_len > 0:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_review_purchaseSaleStatus_normal(self):
        """case54 检核工作台，待检核购销状态-为正常销售状态查询"""
        r = backlog.review_query(purchaseSaleStatus=3)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        re_len = len(res['data']['list'])
        if re_len > 0:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_review_purchaseSaleStatus_temp(self):
        """case55 检核工作台，待检核购销状态-临时缺货状态查询"""
        r = backlog.review_query(purchaseSaleStatus=5)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        re_len = len(res['data']['list'])
        if re_len > 0:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_review_by_name(self):
        """case56 检核工作台，待检核按名称搜索"""
        res_a = backlog.review_query()
        name = res_a[0].json()['data']['list'][0]['productName']
        if name:
            r = backlog.review_query(productName=name)
            self.url = r[1]
            self.data = r[2]
            res = r[0].json()
            re_len = len(res['data']['list'])
            if re_len > 0:
                self.time = r[0].elapsed.total_seconds()
                self.result = {"success": True}
            else:
                self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_review_by_sku(self):
        """case57 检核工作台，待检核按sku搜索"""
        res_a = backlog.review_query()
        sku = res_a[0].json()['data']['list'][0]['skuCode']
        if sku:
            r = backlog.review_query(skuCode=sku)
            self.url = r[1]
            self.data = r[2]
            res = r[0].json()
            re_len = len(res['data']['list'])
            if re_len > 0:
                self.time = r[0].elapsed.total_seconds()
                self.result = {"success": True}
            else:
                self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_review_by_spu(self):
        """case58 检核工作台，待检核按spu搜索"""
        res_a = backlog.review_query()
        sku = res_a[0].json()['data']['list'][0]['skuCode']
        spu = sku[0:-3]
        if spu:
            r = backlog.review_query(spuCodes=spu)
            self.url = r[1]
            self.data = r[2]
            res = r[0].json()
            re_len = len(res['data']['list'])
            if re_len > 0:
                self.time = r[0].elapsed.total_seconds()
                self.result = {"success": True}
            else:
                self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_review_by_sourceType_yu(self):
        """case59 检核工作台，待检核按货源类型为预售搜索"""
        r = backlog.review_query(sourceType=0)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        sourceType = res['data']['list'][0]['sourceType']
        if sourceType == "预售":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_review_by_sourceType_xian(self):
        """case60 检核工作台，待检核按货源类型为线上现货搜索"""
        r = backlog.review_query(sourceType=1)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        sourceType = res['data']['list'][0]['sourceType']
        if sourceType == "线上现货":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_review_by_sourceType_tui(self):
        """case61 检核工作台，待检核按货源类型为供应商推品搜索"""
        r = backlog.review_query(sourceType=2)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        sourceType = res['data']['list'][0]['sourceType']
        if sourceType == "供应商推品":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_review_by_sourceType_zi(self):
        """case62 检核工作台，待检核按货源类型为自主开发搜索"""
        r = backlog.review_query(sourceType=3)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        sourceType = res['data']['list'][0]['sourceType']
        if sourceType == "自主开发":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    # @ReRun(MyTest.setUp)
    # def test_review_by_categoryIds(self):
    #     """case63 检核工作台，待检核商品品类或商品分类搜索"""
    #     res_a = backlog.review_query()
    #     categoryName = res_a[0].json()['data']['list'][0]['categoryName']
    #     #根据categoryName查询分类的id
        